var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("BaseModuleUI"),
    n = e("GlobalParams"),
    i = e("CommonHelper"),
    r = e("PureHelper"),
    s = cc._decorator,
    l = s.ccclass,
    _ = s.property,
    c = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.ai_hero_ske = null), (t.role_move = !1), (t.moveDir = new cc.Vec2(0, 0)), (t.traget_pos = null), t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                e.prototype.initView.call(this), this.updateTime(), this.showAiAction();
            }),
            (t.prototype.showAiAction = function () {
                var e = this;
                i.default.getRandomInt(0, 8) < 3
                    ? (this.ai_hero_ske.setAnimation(0, "battle_idle", !0),
                        this.scheduleOnce(function () {
                            e.showAiAction();
                        }, i.default.getRandomInt(5, 10)))
                    : ((this.role_move = !0),
                        this.ai_hero_ske.setAnimation(0, "run", !0),
                        (this.traget_pos = cc.v2(
                            i.default.getRandomInt(-1100, 1100),
                            i.default.getRandomInt(-380, 130)
                        )));
            }),
            (t.prototype.updateTime = function () {
                var e = this;
                this.role_move &&
                    (r.default.Distance(this.node.getPosition(), this.traget_pos) < 50
                        ? ((this.role_move = !1), this.showAiAction())
                        : ((this.moveDir = cc
                            .v2(this.traget_pos.x, this.traget_pos.y)
                            .sub(this.node.getPosition())
                            .normalize()),
                            this.roleMove())),
                    this.scheduleOnce(function () {
                        e.updateTime();
                    }, n.GlobalParams.GameUpdateTime);
            }),
            (t.prototype.roleMove = function () {
                0 != this.moveDir.x &&
                    (this.ai_hero_ske.node.scaleX =
                        Math.abs(this.ai_hero_ske.node.scaleX) * (this.moveDir.x < 0 ? 1 : -1));
                var e = this.node.getPosition().add(this.moveDir.mul(30));
                (e.x = e.x < -1170 ? -1170 : e.x),
                    (e.x = e.x > 1170 ? 1170 : e.x),
                    (e.y = e.y > 130 ? 130 : e.y),
                    (e.y = e.y < -380 ? -380 : e.y),
                    cc
                        .tween(this.node)
                        .to(n.GlobalParams.GameUpdateTime, { position: cc.v2(e.x, e.y) })
                        .start();
            }),
            oo([_(sp.Skeleton)], t.prototype, "ai_hero_ske", void 0),
            oo([l], t)
        );
    })(a.default);
o.default = c;
